import router from './router'
import store from './store'
import NProgress from 'nprogress' // 进度条
import 'nprogress/nprogress.css' // 进度条样式
import { Message } from 'element-ui'
import { getToken } from '@/utils/auth' // 验权

const whiteList = ['login']
router.beforeEach((to,from,next) => {
  NProgress.start()
  console.log('token : ' + getToken())
  if (getToken()) {
    if (to.path === '/login') {
      next({path: '/'})
      NProgress.done()
    }else {
      if (store.getters.roles.length === 0) {
        // TODO 获取用户信息
      }
      next()
      NProgress.done()
    }
  } else {
    next({path: '/login'})
    NProgress.done()
  }
})
